// pages/personaltailor/personaltailor.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    subMenuDisplay:['show','show','show'],
    basicInfo:[{
      text:'手机号',
      value:'',
      name:'telphone'
    },{
      text: '姓名',
      value: '',
      name: 'name'
    }],
    travelType:[{
      text: '家庭出游',
      
    },{
      text: '朋友结伴',
      
    },{
      text: '公司旅游',
      
    },{
      text: '其他',
      
    }],
    selectedIndex:-1,
    startDate: '',
    travelPlan: [{
      text: '逗留时长(天)',
      value: '',
      placeholder:'预计天数',
      name: 'day_num'
    }, {
      text: '人数',
      value: '',
      placeholder: '预计人数',
      name: 'per_num'
    },{
      text: '预算',
      value: '',
      placeholder: '预算',
      name: 'budget'
    }],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  showContent:function(e){
    console.log(e);
    var index = e.target.dataset.index;
    index = parseInt(index);

    var display = this.data.subMenuDisplay;
    display[index] = display[index]=='show'?'hidden':'show';
    
    this.setData({
      subMenuDisplay: display
    })

    console.log(this.data.subMenuDisplay);
  }, 
  checkboxChange:function(e){
    console.log(e);
    var index = e.target.dataset.index;
    index = parseInt(index);

    this.setData({
      selectedIndex: index
    }) 
  },
  commitInfo:function(){
    console.log(this.data.basicInfo,this.data.selectedIndex,this.data.travelPlan);

    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2]; //上一个页面
    
    console.log(pages);

    prevPage.setData({
      currentTab: 2
    })
    wx.navigateBack({
      delta: 1
    });
  },
  inputBlur:function(e){
    console.log(e);
    var result = e.detail.value;
    var name = e.target.dataset.name;
    var str;
    switch (name){
      case 'telphone':
        str= 'basicInfo[0].value';
        break;
      case 'name':
        str = 'basicInfo[1].value';
        break;
      case 'day_num':
        str = 'travelPlan[0].value';
        break;
      case 'per_num':
        str = 'travelPlan[1].value';
        break;
      case 'budget':
        str = 'travelPlan[2].value';
        break;  
    }
    this.setData({
      [str]: result
    })
  },
  //选择出行日期
  bindDateChange: function (e) {
    console.log(e.detail.value);
    this.setData({
      startDate: e.detail.value
    })
  },
  //获取当前时间
  getData: function () {
    var date = new Date();
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate();

    var r = year + '-' + month + '-' + day
    this.setData({
      startDate: r
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})